<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 算数运算符, + - * / %
        let num2 = 13.12, num3 = 99;
        let str2 = " 字符串";

        console.log(num2 + num3);

        console.log(num2 * num3);
        console.log((num2 * num3).toFixed(2));

        console.log(num3 / 10);
        console.log((num3 - num3 % 10) / 10);
        console.log(parseInt(num3 / 10));

        console.log(num2 + str2);
        console.log(str2 + num2 + ",");

        console.log(num2 + '2');
        console.log(num2 * '2');
        console.log('2' * num2);

        // 条件分支，if else
        // 关系运算符：== === != !== > >= < >=
        // 逻辑运算符：&& || !

        var num = 12;
        if (num > 9 && num < 20) {
            console.log('（9，20）');
        }

        if (num <= 9 || num >= 20) {
            console.log('（-oo, 9], [20, +oo)');
        }

        if (!(num <= 9 || num >= 20)) {
            console.log('（9，20）');
        }


        if (num > 9) {
            console.log('Bigger than 9');
        } else if (num > 5) {
            console.log('Between 5 and 9');
        } else {
            console.log('Small than 5');
        }

        console.log(num == 9);
        console.log(num === 9);
        console.log(num != 9);
        console.log(num !== 9);
        console.log(num > 9);
        console.log(num >= 9);
        console.log(num < 9);
        console.log(num <= 9);

        if ('12' == 12) {
            console.log('Equal!')
        } else {
            console.log('NOT Equal!')
        }

        if ('12' === 12) {
            console.log('Equal!')
        } else {
            console.log('NOT Equal!')
        }


        // 三目运算符
        let resNum = num > 10 ? 'OK' : 'Bad';
        console.log('resNum: ' + resNum);

        // 条件分支，switch case
        switch (num) {
            case 1, 2, 3, 4, 5, 6, 7:
                console.log('bad');
                break;
            case 8, 9, 10, 11, 12:
                console.log('good');
                break;
            default:
                console.log('excellent');
        }

        let studentType = 'college';
        switch (studentType) {
            case 'college':
                console.log('大学生');
                break;
            case 'student':
                console.log('其他学生');
                break;
            default:
                console.log('不是学生');
        }

        // 循环 while for
        let sum = 0, i = 0;
        while (i < 10) {
            sum += i;
            i++;
        }
        console.log("sum = " + sum);

        sum = 0;
        for (let k = 0; k < 10; k++) {
            sum += k;
        }
        console.log("sum = " + sum);


        // 处理空的问题
        let empty = false;
        // let empty = 0;
        // let empty = null;
        // let empty = NaN;
        // let empty;
        // let empty = undefined;
        // let empty = "";

        if (empty) {
            console.log("OK");
        } else {
            console.log("Empty!!");
        }


    </script>
</body>

</html>